<template>
	<view>
		<u-sticky bgColor="#6492FF" offsetTop=0 customNavHeight=0>
			<navbox title="实名认证"></navbox>
		</u-sticky>
		<view class="con">
			<!-- <view class="con__top">
				<view class="u-flex u-flex-y-center c649">
					<image class="con__top__smrz" src="/static/img/my/smrz.png" mode=""></image>
					实名认证
				</view>
				<image class="con__top__sy" src="/static/img/my/sy.png" mode=""></image>
				<view class="u-flex u-flex-y-center c707">
					<image class="con__top__zxqy" src="/static/img/my/qy.png" mode=""></image>
					在线签约
				</view>
			</view> -->
			<view class="con__title">
				实名认证
			</view>
			<view class="con__ms">
				需要实名认证，是因为我方帮您的佣金进行了完税，让您的佣金合规合法
			</view>
			<view class="con__box">
				<view class="con__box__item">
					<view class="con__item__label">
						真实姓名
					</view>
					<input type="text" :disabled="disabled" v-model="form.name" class="con__box__item__value" placeholder="请输入真实姓名" placeholder-style="font-size:26rpx" />
				</view>
				<view class="con__box__item">
					<view class="con__item__label">
						身份证号码
					</view>
					<input type="number" :disabled="disabled" v-model="form.creditId" class="con__box__item__value" placeholder="请输入身份证号码" placeholder-style="font-size:26rpx" />
				</view>
				<view class="con__item__label" style="line-height: 70rpx;">
					证件照片
					<text style="color: #707070;font-size: 25rpx;">（点击身份证正面或反面上传对应照片）</text>
				</view>
				<view class="u-flex u-flex-y-center u-flex-between" style="margin-top: 6rpx;">
					<view class="" @click="clicktp(1)" style="position: relative;">
						<image :src="form.creditFront?form.creditFront:'/static/img/my/shilie.png'" class="con__shili" mode=""></image>
						<view class="con__shili__ms">
							身份证正面
						</view>
					</view>
					<view class="" @click="clicktp(2)" style="position: relative;">
						<image :src="form.creditBack?form.creditBack:'/static/img/my/shilie.png'" class="con__shili" mode=""></image>
						<view class="con__shili__ms">
							身份证反面
						</view>
					</view>
				</view>
				<view class="u-flex u-flex-y-center u-flex-between" style="margin-top: 23rpx;" v-if="user.credit==0">
					<view v-for="(item,index) in sllist" :key="index" style="position: relative;">
						<image src="/static/img/my/shilie.png" class="con__shili1" mode=""></image>
						<view class="con__shili1__ms">
							{{item.name}}
						</view>
						<image v-if="index==0" src="/static/img/my/dui.png" class="con__shili1__dui" mode=""></image>
						<image v-else src="/static/img/my/cuo.png" class="con__shili1__dui" mode=""></image>
					</view>
				</view>
			</view>
			<view class="con__footer" v-if="user.credit==0">
				<u-button text="提交认证" @click="submit" color="#6492FF" shape='circle'></u-button>
			</view>
		</view>
	</view>
</template>

<script> 
	import {credit} from '@/api/user.js'
	export default {
		data() {
			return {
				sllist:[
					{name:'正确示范'},
					{name:'图片缺失'},
					{name:'照片模糊'},
					{name:'反光强烈'},
				],
				user:{},
				form:{
					name:'',
					creditId:'',
					creditBack:'',
					creditFront:''
				},
				disabled:false
			};
		},
		onLoad() {
			this.user=uni.getStorageSync('ytbuser')
			if(this.user.credit==1){
				this.disabled=true
				for (let key in this.form) {
					this.form[key]=this.user[key]
				}
			}
			
		},
		methods:{
			submit(){
				let {name,creditId,creditBack,creditFront} = this.form
				if(!name){
					this.$u.toast('请输入姓名')
					return
				}
				if(creditId.length<18){
					this.$u.toast('身份证号码不正确')
					return
				}
				if(!creditBack){
					this.$u.toast('请上传身份证国徽面照片')
					return
				}
				if(!creditFront){
					this.$u.toast('请上传身份证人像面照片')
					return
				}
				
				credit(this.form).then(res=>{
					if(res.data.code==200){
						this.$u.toast('认证成功')
						this.getuserinfo()
						setTimeout(()=>{
							uni.navigateBack()
						},200)
					}else{
						this.$u.toast(res.data.msg)
					}
				})
			},
			clicktp(type){
				if(type==1){//正面
					if(this.user.credit==1){
						this.imgPreview([this.user.creditFront],0)
						return
					}
					this.upimg('creditFront')
				}
				if(type==2){//反面
					if(this.user.credit==1){
						this.imgPreview([this.user.creditBack],0)
						return
					}
					this.upimg('creditBack')
				}
			},
			upimg(type) {
				let _this = this
				uni.chooseImage({
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						uni.showLoading({
							title: '上传中'
						})
						uni.uploadFile({
							url: _this.$BASE_URL + '/app/upload', //仅为示例，非真实的接口地址
							filePath: tempFilePaths[0],
							name: 'file',
							header: {
								Authorization: uni.getStorageSync('ytbtoken')
							},
							success: (uploadFileRes) => {
								if (JSON.parse(uploadFileRes.data).code == 200) {
									uni.hideLoading()
									_this.form[type] = JSON.parse(uploadFileRes.data)
										.data.url
									_this.$forceUpdate()
								}else{
									uni.reLaunch({
										url:'/pages/index/login'
									})
								}
							}
						});
					}
				});
			},
		}
	}
</script>

<style lang="scss">
page{
	background-color: #f6f6f6;
	
}
.con{
	padding: 25rpx 16rpx;
	&__top{
		height: 78.47rpx;
		padding:0 114rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		background: #FFFFFF;
		border-radius: 14rpx;
		font-family: Source Han Sans SC;
		font-weight: bold;
		font-size: 26rpx;
		line-height: 26rpx;
		
		&__smrz{
			width: 31rpx;
			height: 38rpx;
			margin-right: 14rpx;
		}
		&__zxqy{
			width: 36.81rpx;
			height: 32.64rpx;
			margin-right: 14rpx;
		}
		&__sy{
			width: 20.83rpx;
			height: 23.61rpx;
		}
	}
	&__title{
		font-family: Source Han Sans SC;
		font-weight: 400;
		font-size: 33rpx;
		color: #3E3D3D;
		line-height: 33rpx;
		margin-top: 48rpx;
	}
	&__ms{
		font-family: Source Han Sans SC;
		font-weight: 400;
		font-size: 25rpx;
		color: #3E3D3D;
		line-height: 42rpx;
		margin-top: 16rpx;
		text-indent: 2rem;
		padding-right: 30rpx;
	}
	&__box{
		margin-top: 25rpx;
		background: #FFFFFF;
		border-radius: 14rpx;
		padding: 30rpx 40rpx 40rpx;
		&__item{
			display: flex;
			align-items: center;
			justify-content: space-between;
			border-bottom: 1rpx solid rgba(205, 205, 205, .5);
			height: 70rpx;
			&__label{
				font-family: Source Han Sans SC;
				font-weight: 400;
				font-size: 26rpx;
				color: #3E3D3D;
				line-height: 26rpx;
			}
			&__value{
				width: 60%;
				font-family: Source Han Sans SC;
				font-weight: 400;
				font-size: 26rpx;
				color: #707070;
				text-align: right;
			}
			
		}
		
	}
	&__shili{
		width: 286.11rpx;
		height: 185.42rpx;
		&__ms{
			position: absolute;
			left: 0;
			bottom: 0;
			width: 286rpx;
			height: 27rpx;
			background: #707070;
			opacity: 0.7;
			font-family: Source Han Sans SC;
			font-weight: 400;
			font-size: 17rpx;
			color: #FFFFFF;
			line-height: 27rpx;
			text-align: center;
		}
	}
	&__shili1{
		width: 141.67rpx;
		height: 86.81rpx;
		&__ms{
			font-family: Source Han Sans SC;
			font-weight: 400;
			font-size: 25rpx;
			color: #707070;
			line-height: 40rpx;
			text-align: center;
		}
		&__dui{
			width: 38.89rpx;
			height: 25.69rpx;
			position: absolute;
			top: 30rpx;
			left: 52rpx;
		}
		&__cuo{
			width: 32.64rpx;
			height: 32.64rpx;
			position: absolute;
			top: 28rpx;
			left: 54rpx;
		}
	}
	&__footer{
		padding: 25rpx 100rpx;
		
	}
}
.c707{
	color: #707070;
}
.c649{
	color: #6492FF;
}
</style>
